package com.hongxun.design.listeners;

import android.view.View;

import com.alibaba.fastjson.JSON;
import com.hongxun.design.MyApp;
import com.hongxun.design.bean.PhotoBean;
import com.hongxun.design.bean.PhotoGraphBean;
import com.hongxun.design.constant.Constant;
import com.hongxun.design.mytools.MString;
import com.hongxun.design.mytools.MyLog;
import com.hongxun.design.mytools.ToastShow;
import com.hongxun.design.utils.PhotosActivityUtil;
import com.hongxun.design.utils.PopwindowUtil;

/**
 * Created by zerdoor_pc on 2016/5/11.
 */
public class ClickToActivity implements View.OnClickListener {
    private int TYPE;
    private PhotoBean bean;
    private PhotoGraphBean photoGraphBean;

    public ClickToActivity(int type) {
        this.TYPE = type;
    }

    public ClickToActivity(int type, PhotoBean bean) {
        this.TYPE = type;
        this.bean = bean;
    }

    public ClickToActivity(int type, PhotoGraphBean bean) {
        this.TYPE = type;
        this.photoGraphBean = bean;
    }

    @Override
    public void onClick(View view) {
        if (MyApp.activity == null) return;
//        Bundle bundle = new Bundle();
        if (MyApp.currExploration.getExploration_id() == null) {
            ToastShow.showShort(MyApp.activity, "踏勘点不存在！");
            return;
        }
        if (photoGraphBean == null && bean == null) {
//            bundle.putInt(MString.ISEDIT, Constant.CREATE);
//            bundle.putString(MString.PATH, "");
            MyLog.L(MString.SUCCESSED + "null=" + TYPE + "   " + Constant.CREATE);
            PhotosActivityUtil.IntentToEditImageActivity(MyApp.activity, "", TYPE, Constant.CREATE);
        } else if (bean == null) {
//            bundle.putInt(MString.ISEDIT, Constant.CREATE);
//            bundle.putString(MString.PATH, "");
//            bundle.putString(MString.Photos, JSON.toJSONString(photoGraphBean));
            MyLog.L(MString.SUCCESSED + "beannull=" + TYPE + "   " + Constant.CREATE + "  " + JSON.toJSONString(photoGraphBean));
            PhotosActivityUtil.IntentToEditImageActivity(MyApp.activity, "", TYPE, Constant.CREATE, JSON.toJSONString(photoGraphBean));
        } else {
//            bundle.putInt(MString.ISEDIT, Constant.EDIT);
//            bundle.putString(MString.PATH, bean.getUrl());
            MyLog.L(MString.SUCCESSED + "v=" + TYPE + "   " + Constant.CREATE + "  " + bean.getUrl());
            PhotosActivityUtil.IntentToEditImageActivity(MyApp.activity, bean.getUrl(), bean.getPhoto_id(), bean.getUuid(), TYPE, Constant.EDIT);
        }

        // bundle.putInt(MString.CODE, TYPE);
//        IntentToActivity.intent(MyApp.activity, EditImageActivity.class, bundle);


        if (PopwindowUtil.titlePopup != null) PopwindowUtil.titlePopup.dismiss();
    }
}

